package com.xps.charmingshop.view.fragment;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.orhanobut.dialogplus.DialogPlus;
import com.orhanobut.dialogplus.OnClickListener;
import com.xps.charmingshop.R;
import com.xps.charmingshop.bean.ShopBean;
import com.xps.charmingshop.date.net.UserNetWorks;
import com.xps.charmingshop.utils.SharedPreferencesUtils;
import com.xps.charmingshop.view.base.BaseFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import rx.Subscriber;

/**
 * Created by MI on 2018/1/10.
 */

public class ShopFragment extends BaseFragment {
    @BindView(R.id.Text_State)
    TextView TextState;
    @BindView(R.id.Text_Morning)
    TextView TextMorning;
    @BindView(R.id.Text_Night)
    TextView TextNight;
    @BindView(R.id.Text_Address)
    TextView TextAddress;
    Unbinder unbinder;

    @Override
    protected int getRes() {
        return R.layout.fragment_shop;
    }

    @Override
    protected void init(View view) {
        unbinder = ButterKnife.bind(this, view);
        getShop();
    }

    @Override
    protected void setData(View view) {

    }

    @Override
    public void onClick(View v) {

    }

    public void hide() {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.hide(this);
        fragmentTransaction.commit();
    }

    void getShop() {
        String user_token = SharedPreferencesUtils.getString("user_token", "String", null);
        UserNetWorks.getShop(user_token, new Subscriber<ShopBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onNext(ShopBean shopBean) {

                if (shopBean.getReturn_code().equals("SUCCESS")) {
                    if (shopBean.getReturn_body().getShop_status().equals("1")) {
                        TextState.setText("正常");
                    } else if (shopBean.getReturn_body().getShop_status().equals("0")) {
                        TextState.setText("待审核");
                    } else if (shopBean.getReturn_body().getShop_status().equals("2")) {
                        TextState.setText("不公开");
                    }
                    TextMorning.setText(shopBean.getReturn_body().getShop_open_time() + "");
                    TextNight.setText(shopBean.getReturn_body().getShop_close_time() + "");
                    TextAddress.setText(shopBean.getReturn_body().getShop_address() + "");
                } else if (shopBean.getReturn_code().equals("FAIL")) {


                }

            }
        });
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.Text_State, R.id.Text_Morning, R.id.Text_Night, R.id.Text_Address})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.Text_State:
                break;
            case R.id.Text_Morning:
                break;
            case R.id.Text_Night:
                break;
            case R.id.Text_Address:
                break;
        }
    }
}
